const http = require('http');
const fs = require('fs');
const zlib = require('zlib');
const url = require('url');

http.createServer((req, res) => {
  let { pathname } = url.parse(req.url, true);
  console.log(pathname);
  let rs = fs.createReadStream(`www${pathname}`);

  rs.on('error', () => {
    res.writeHeader(404);
    res.write('not found');
    res.end()
  })
  res.setHeader('content-encoding', 'gzip');
  let gz = zlib.createGzip();
  // res.setHeader('content-encoding', 'gzip');
  // let gz = zlib.createGzip();


  rs.pipe(gz).pipe(res)


}).listen(9111)